/**
 * @(#)HelloWorldServer.java, 2019/1/7
 * <p/>
 * Copyright 2019 Netease, Inc. All rights reserved.
 * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.chengzhi.netty.grpc;

import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.IOException;

/**
 * @author 阮承志(wb.ruanchengzhi @ mesg.corp.netease.com)
 **/
public class HelloWorldServer {
    private static Server server;

    public static void main(String[] args) throws IOException, InterruptedException {
        server = ServerBuilder.forPort(8888)
                .addService(new GreeTerImpl())
                .build()
                .start();
        System.out.println("server start -------------");
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                HelloWorldServer.stop();
            }
        });
        server.awaitTermination();
    }

    private static void stop() {
        if (server != null) {
            server.shutdown();
        }
    }
}
